package ui;

import entity.Student;
import service.StudentService;
import service.impl.StudentServiceImpl;

import java.util.Scanner;

public class RegisterMenu {
    private static final StudentService studentService = new StudentServiceImpl();

    public static void showRegisterMenu() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("--------注册界面--------");
        System.out.println("--------输入姓名--------");
        String userName = scanner.next();
        System.out.println("--------输入密码--------");
        String userPassword = scanner.next();
        System.out.println("--------输入邮箱--------");
        String email = scanner.next();
        Student student = new Student();
        student.setId(null);
        student.setName(userName);
        student.setPassword(userPassword);
        student.setEmail(email);
        try {
            studentService.register(student);
            System.out.println("--------注册成功--------");
            StartMenu.showStartMenu();
        } catch (Exception e) {
            System.out.println(e.getMessage());
            showRegisterMenu();
        }
    }
}
